package com.client.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;


import com.mysql.jdbc.Statement;


public class JdbcUtil {
	
	private static String driver = "com.mysql.jdbc.Driver";
	private static String url = "jdbc:mysql://localhost:3306/enterprisechat?useUnicode=true&characterEncoding=utf8";
	private static String username = "root";
	private static String password = "";
	
	
	static {
		
		try {

			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	
	public static Connection getConnection() {
		try {

			Connection conn = DriverManager.getConnection(url, username, password);
			return conn;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return null;
		
	}


	public static void close(Object obj) {
		if(obj == null) {
			return;
		}
		

		
		try {
			if(obj instanceof Connection) {
				((Connection)obj).close();
			} else if(obj instanceof Statement) {
				((Statement)obj).close();
			} else if(obj instanceof ResultSet) {
				((ResultSet)obj).close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	

}
